﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.ComponentModel;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows;
using System.Collections.ObjectModel;
using OperGui.ViewModel;
using System.Windows.Controls;
using OperGui.Models;



namespace OperGui
{
    public class MainWindowViewModel : ViewModelBase
    {
        #region field
        Timecontrol _time;
        FrameworkElement _currentView;
        string _performance;
        public string NVB;
        
        public int listN;
        
        double x;
        double y;
    //------------





        public double Wid
        {
            get { x = System.Windows.SystemParameters.PrimaryScreenWidth; return x ; }

        }


        public double Hei
        {
            get { y = System.Windows.SystemParameters.PrimaryScreenHeight; return y ; }
        }

        #endregion
        ObservableCollection<CommandViewModel> _commands;
        #region constructor
        public MainWindowViewModel()
        {
            CurrentView = new Views.GroupView(null);
            Commands.Add(new CommandViewModel("Initial Page", null, new RelayCommand(e => this.ViewSwitch("Initial Page"))));
            _time = new Timecontrol();
           
            
        }
        #endregion
        
        
        
        // 13:55
        public ObservableCollection<CommandViewModel> Commands
        {
            get
            {
                if (_commands == null)
                {
                    List<CommandViewModel> cmds = this.CreateCommands();
                    _commands = new ObservableCollection<CommandViewModel>(cmds);
                }
                return _commands;
            }
        }

     
        List<CommandViewModel> CreateCommands()
        {
            return new List<CommandViewModel>
            {
                
                   
                
            };
        }

//
      



        public Timecontrol TimeControl
        {
            get { return _time; }
        }

        public ICommand switchView
        {
            get { return new RelayCommand(OnViewSwitch) as ICommand; }
        }


        void ViewSwitch(string NVID)
        {
            
            int s = 0, N = Commands.Count;
            foreach (CommandViewModel a in Commands)
            {
                if (a.DisplayName == NVID)
                {
                    s = Commands.IndexOf(a);
                }
            }
            for (int x = N - 1; x > s; x--)
            {
                Commands.RemoveAt(x);
            }

           if(NVID == "Initial Page")
           {
               CurrentView = new Views.GroupView(null);
           }
           else
           {
               if (Commands[s].TType== "Group")
                {
                    CurrentView = new Views.TilesView(NVID);
                }
                else if (Commands[s].TType == "Zone")
                {
                    CurrentView = new Views.ElementView(NVID);
                }

           }
        }

        void OnViewSwitch(object view)
        {

            x = System.Windows.SystemParameters.PrimaryScreenWidth; 
                Button _tile = view as Button;
                Grid _Content = _tile.Content as Grid;
                string NVID = _tile.Tag.ToString();

                NVB = _tile.Background.ToString();
                //NVA = _tile.AllowDrop.ToString();
                 if (NVB == "#FFFF0000")
                {
                    
                    CurrentView = new Views.TilesView(NVID);
                    Commands.Add(new CommandViewModel(NVID, "Group",new RelayCommand(e => this.ViewSwitch(NVID))));
                }

                else if (NVB == "#FF0000FF")
                {
                  
                    CurrentView = new Views.ElementView(NVID);
                    Commands.Add(new CommandViewModel(NVID,"Zone", new RelayCommand(e => this.ViewSwitch(NVID))));
                
                }
            
             
       }


        public FrameworkElement CurrentView
        {
            get { return _currentView; }
            set { _currentView = value; base.OnPropertyChanged("CurrentView"); }
        }

        public string performance
        { get { return _performance; } set { _performance = value; OnPropertyChanged("performance"); } }


        public string NVNC { get; set; }
    }
}
